* Introducing bit field for database parameters
[lhc/web/wiklou.git] / includes / Article.php
1 <?php
2 # $Id$
3 #
4 # Class representing a Wikipedia article and history.
5 # See design.doc for an overview.
6
7 # Note: edit user interface and cache support functions have been
8 # moved to separate EditPage and CacheManager classes.
9
10 require_once ( 'CacheManager.php' );
11 include_once ( 'SpecialValidate.php' ) ;
12
13 $wgArticleCurContentFields = false;
14 $wgArticleOldContentFields = false;
15
16 class Article {
17 /* private */ var $mContent, $mContentLoaded;
18 /* private */ var $mUser, $mTimestamp, $mUserText;
19 /* private */ var $mCounter, $mComment, $mCountAdjustment;
20 /* private */ var $mMinorEdit, $mRedirectedFrom;
21 /* private */ var $mTouched, $mFileCache, $mTitle;
22 /* private */ var $mId, $mTable;
23
24 function Article( &$title ) {
25 $this->mTitle =& $title;
26 $this->clear();
27 }
28
29 /* private */ function clear()
30 {
31 $this->mContentLoaded = false;
32 $this->mCurID = $this->mUser = $this->mCounter = -1; # Not loaded
33 $this->mRedirectedFrom = $this->mUserText =
34 $this->mTimestamp = $this->mComment = $this->mFileCache = '';
35 $this->mCountAdjustment = 0;
36 $this->mTouched = '19700101000000';
37 }
38
39 # Get revision text associated with an old or archive row
40 # $row is usually an object from wfFetchRow(), both the flags and the text field must be included
41 /* static */ function getRevisionText( $row, $prefix = 'old_' ) {
42 # Get data
43 $textField = $prefix . 'text';
44 $flagsField = $prefix . 'flags';
45
46 if ( isset( $row->$flagsField ) ) {
47 $flags = explode( ",", $row->$flagsField );
48 } else {
49 $flags = array();
50 }
51
52 if ( isset( $row->$textField ) ) {
53 $text = $row->$textField;
54 } else {
55 return false;
56 }
57
58 if ( in_array( 'link', $flags ) ) {
59 # Handle link type
60 $text = Article::followLink( $text );
61 } elseif ( in_array( 'gzip', $flags ) ) {
62 # Deal with optional compression of archived pages.
63 # This can be done periodically via maintenance/compressOld.php, and
64 # as pages are saved if $wgCompressRevisions is set.
65 return gzinflate( $text );
66 }
67 return $text;
68 }
69
70 /* static */ function compressRevisionText( &$text ) {
71 global $wgCompressRevisions;
72 if( !$wgCompressRevisions ) {
73 return '';
74 }
75 if( !function_exists( 'gzdeflate' ) ) {
76 wfDebug( "Article::compressRevisionText() -- no zlib support, not compressing\n" );
77 return '';
78 }
79 $text = gzdeflate( $text );
80 return 'gzip';
81 }
82
83 # Returns the text associated with a "link" type old table row
84 /* static */ function followLink( $link ) {
85 # Split the link into fields and values
86 $lines = explode( '\n', $link );
87 $hash = '';
88 $locations = array();
89 foreach ( $lines as $line ) {
90 # Comments
91 if ( $line{0} == '#' ) {
92 continue;
93 }
94 # Field/value pairs
95 if ( preg_match( '/^(.*?)\s*:\s*(.*)$/', $line, $matches ) ) {
96 $field = strtolower($matches[1]);
97 $value = $matches[2];
98 if ( $field == 'hash' ) {
99 $hash = $value;
100 } elseif ( $field == 'location' ) {
101 $locations[] = $value;
102 }
103 }
104 }
105
106 if ( $hash === '' ) {
107 return false;
108 }
109
110 # Look in each specified location for the text
111 $text = false;
112 foreach ( $locations as $location ) {
113 $text = Article::fetchFromLocation( $location, $hash );
114 if ( $text !== false ) {
115 break;
116 }
117 }
118
119 return $text;
120 }
121
122 /* static */ function fetchFromLocation( $location, $hash ) {
123 global $wgLoadBalancer;
124 $fname = 'fetchFromLocation';
125 wfProfileIn( $fname );
126
127 $p = strpos( $location, ':' );
128 if ( $p === false ) {
129 wfProfileOut( $fname );
130 return false;
131 }
132
133 $type = substr( $location, 0, $p );
134 $text = false;
135 switch ( $type ) {
136 case 'mysql':
137 # MySQL locations are specified by mysql://<machineID>/<dbname>/<tblname>/<index>
138 # Machine ID 0 is the current connection
139 if ( preg_match( '/^mysql:\/\/(\d+)\/([A-Za-z_]+)\/([A-Za-z_]+)\/([A-Za-z_]+)$/',
140 $location, $matches ) ) {
141 $machineID = $matches[1];
142 $dbName = $matches[2];
143 $tblName = $matches[3];
144 $index = $matches[4];
145 if ( $machineID == 0 ) {
146 # Current connection
147 $db =& wfGetDB( DB_SLAVE );
148 } else {
149 # Alternate connection
150 $db =& $wgLoadBalancer->getConnection( $machineID );
151
152 if ( array_key_exists( $machineId, $wgKnownMysqlServers ) ) {
153 # Try to open, return false on failure
154 $params = $wgKnownDBServers[$machineId];
155 $db = Database::newFromParams( $params['server'], $params['user'], $params['password'],
156 $dbName, 1, DBO_IGNORE );
157 }
158 }
159 if ( $db->isOpen() ) {
160 $index = $db->strencode( $index );
161 $res = $db->query( "SELECT blob_data FROM $dbName.$tblName WHERE blob_index='$index'", $fname );
162 $row = $db->fetchObject( $res );
163 $text = $row->text_data;
164 }
165 }
166 break;
167 case 'file':
168 # File locations are of the form file://<filename>, relative to the current directory
169 if ( preg_match( '/^file:\/\/(.*)$', $location, $matches ) )
170 $filename = strstr( $location, 'file://' );
171 $text = @file_get_contents( $matches[1] );
172 }
173 if ( $text !== false ) {
174 # Got text, now we need to interpret it
175 # The first line contains information about how to do this
176 $p = strpos( $text, '\n' );
177 $type = substr( $text, 0, $p );
178 $text = substr( $text, $p + 1 );
179 switch ( $type ) {
180 case 'plain':
181 break;
182 case 'gzip':
183 $text = gzinflate( $text );
184 break;
185 case 'object':
186 $object = unserialize( $text );
187 $text = $object->getItem( $hash );
188 break;
189 default:
190 $text = false;
191 }
192 }
193 wfProfileOut( $fname );
194 return $text;
195 }
196
197 # Note that getContent/loadContent may follow redirects if
198 # not told otherwise, and so may cause a change to mTitle.
199
200 # Return the text of this revision
201 function getContent( $noredir )
202 {
203 global $wgRequest;
204
205 # Get variables from query string :P
206 $action = $wgRequest->getText( 'action', 'view' );
207 $section = $wgRequest->getText( 'section' );
208
209 $fname = 'Article::getContent';
210 wfProfileIn( $fname );
211
212 if ( 0 == $this->getID() ) {
213 if ( 'edit' == $action ) {
214 wfProfileOut( $fname );
215 return ''; # was "newarticletext", now moved above the box)
216 }
217 wfProfileOut( $fname );
218 return wfMsg( 'noarticletext' );
219 } else {
220 $this->loadContent( $noredir );
221
222 if(
223 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
224 ( $this->mTitle->getNamespace() == Namespace::getTalk( Namespace::getUser()) ) &&
225 preg_match('/^\d{1,3}\.\d{1,3}.\d{1,3}\.\d{1,3}$/',$this->mTitle->getText()) &&
226 $action=='view'
227 )
228 {
229 wfProfileOut( $fname );
230 return $this->mContent . "\n" .wfMsg('anontalkpagetext'); }
231 else {
232 if($action=='edit') {
233 if($section!='') {
234 if($section=='new') {
235 wfProfileOut( $fname );
236 return '';
237 }
238
239 # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
240 # comments to be stripped as well)
241 $rv=$this->getSection($this->mContent,$section);
242 wfProfileOut( $fname );
243 return $rv;
244 }
245 }
246 wfProfileOut( $fname );
247 return $this->mContent;
248 }
249 }
250 }
251
252 # This function returns the text of a section, specified by a number ($section).
253 # A section is text under a heading like == Heading == or <h1>Heading</h1>, or
254 # the first section before any such heading (section 0).
255 #
256 # If a section contains subsections, these are also returned.
257 #
258 function getSection($text,$section) {
259
260 # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
261 # comments to be stripped as well)
262 $striparray=array();
263 $parser=new Parser();
264 $parser->mOutputType=OT_WIKI;
265 $striptext=$parser->strip($text, $striparray, true);
266
267 # now that we can be sure that no pseudo-sections are in the source,
268 # split it up by section
269 $secs =
270 preg_split(
271 '/(^=+.*?=+|^<h[1-6].*?' . '>.*?<\/h[1-6].*?' . '>)/mi',
272 $striptext, -1,
273 PREG_SPLIT_DELIM_CAPTURE);
274 if($section==0) {
275 $rv=$secs[0];
276 } else {
277 $headline=$secs[$section*2-1];
278 preg_match( '/^(=+).*?=+|^<h([1-6]).*?' . '>.*?<\/h[1-6].*?' . '>/mi',$headline,$matches);
279 $hlevel=$matches[1];
280
281 # translate wiki heading into level
282 if(strpos($hlevel,'=')!==false) {
283 $hlevel=strlen($hlevel);
284 }
285
286 $rv=$headline. $secs[$section*2];
287 $count=$section+1;
288
289 $break=false;
290 while(!empty($secs[$count*2-1]) && !$break) {
291
292 $subheadline=$secs[$count*2-1];
293 preg_match( '/^(=+).*?=+|^<h([1-6]).*?' . '>.*?<\/h[1-6].*?' . '>/mi',$subheadline,$matches);
294 $subhlevel=$matches[1];
295 if(strpos($subhlevel,'=')!==false) {
296 $subhlevel=strlen($subhlevel);
297 }
298 if($subhlevel > $hlevel) {
299 $rv.=$subheadline.$secs[$count*2];
300 }
301 if($subhlevel <= $hlevel) {
302 $break=true;
303 }
304 $count++;
305
306 }
307 }
308 # reinsert stripped tags
309 $rv=$parser->unstrip($rv,$striparray);
310 $rv=$parser->unstripNoWiki($rv,$striparray);
311 $rv=trim($rv);
312 return $rv;
313
314 }
315
316 # Return an array of the columns of the "cur"-table
317 function &getCurContentFields() {
318 global $wgArticleCurContentFields;
319 if ( !$wgArticleCurContentFields ) {
320 $wgArticleCurContentFields = array( 'cur_text','cur_timestamp','cur_user', 'cur_user_text',
321 'cur_comment','cur_counter','cur_restrictions','cur_touched' );
322 }
323 return $wgArticleCurContentFields;
324 }
325
326 # Return an array of the columns of the "old"-table
327 function &getOldContentFields() {
328 global $wgArticleOldContentFields;
329 if ( !$wgArticleOldContentFields ) {
330 $wgArticleOldContentFields = array( 'old_namespace','old_title','old_text','old_timestamp',
331 'old_user','old_user_text','old_comment','old_flags' );
332 }
333 return $wgArticleOldContentFields;
334 }
335
336 # Load the revision (including cur_text) into this object
337 function loadContent( $noredir = false )
338 {
339 global $wgOut, $wgMwRedir, $wgRequest;
340
341 $dbr =& wfGetDB( DB_SLAVE );
342 # Query variables :P
343 $oldid = $wgRequest->getVal( 'oldid' );
344 $redirect = $wgRequest->getVal( 'redirect' );
345
346 if ( $this->mContentLoaded ) return;
347 $fname = 'Article::loadContent';
348
349 # Pre-fill content with error message so that if something
350 # fails we'll have something telling us what we intended.
351
352 $t = $this->mTitle->getPrefixedText();
353 if ( isset( $oldid ) ) {
354 $oldid = IntVal( $oldid );
355 $t .= ",oldid={$oldid}";
356 }
357 if ( isset( $redirect ) ) {
358 $redirect = ($redirect == 'no') ? 'no' : 'yes';
359 $t .= ",redirect={$redirect}";
360 }
361 $this->mContent = wfMsg( 'missingarticle', $t );
362
363 if ( ! $oldid ) { # Retrieve current version
364 $id = $this->getID();
365 if ( 0 == $id ) return;
366
367 $s = $dbr->getArray( 'cur', $this->getCurContentFields(), array( 'cur_id' => $id ), $fname );
368 if ( $s === false ) {
369 return;
370 }
371
372 # If we got a redirect, follow it (unless we've been told
373 # not to by either the function parameter or the query
374 if ( ( 'no' != $redirect ) && ( false == $noredir ) &&
375 ( $wgMwRedir->matchStart( $s->cur_text ) ) ) {
376 if ( preg_match( '/\\[\\[([^\\]\\|]+)[\\]\\|]/',
377 $s->cur_text, $m ) ) {
378 $rt = Title::newFromText( $m[1] );
379 if( $rt ) {
380 # Gotta hand redirects to special pages differently:
381 # Fill the HTTP response "Location" header and ignore
382 # the rest of the page we're on.
383
384 if ( $rt->getInterwiki() != '' ) {
385 $wgOut->redirect( $rt->getFullURL() ) ;
386 return;
387 }
388 if ( $rt->getNamespace() == Namespace::getSpecial() ) {
389 $wgOut->redirect( $rt->getFullURL() );
390 return;
391 }
392 $rid = $rt->getArticleID();
393 if ( 0 != $rid ) {
394 $redirRow = $dbr->getArray( 'cur', $this->getCurContentFields(), array( 'cur_id' => $rid ), $fname );
395
396 if ( $redirRow !== false ) {
397 $this->mRedirectedFrom = $this->mTitle->getPrefixedText();
398 $this->mTitle = $rt;
399 $s = $redirRow;
400 }
401 }
402 }
403 }
404 }
405
406 $this->mContent = $s->cur_text;
407 $this->mUser = $s->cur_user;
408 $this->mUserText = $s->cur_user_text;
409 $this->mComment = $s->cur_comment;
410 $this->mCounter = $s->cur_counter;
411 $this->mTimestamp = $s->cur_timestamp;
412 $this->mTouched = $s->cur_touched;
413 $this->mTitle->mRestrictions = explode( ',', trim( $s->cur_restrictions ) );
414 $this->mTitle->mRestrictionsLoaded = true;
415 } else { # oldid set, retrieve historical version
416 $s = $dbr->getArray( 'old', $this->getOldContentFields(), array( 'old_id' => $oldid ), $fname );
417 if ( $s === false ) {
418 return;
419 }
420
421 if( $this->mTitle->getNamespace() != $s->old_namespace ||
422 $this->mTitle->getDBkey() != $s->old_title ) {
423 $oldTitle = Title::makeTitle( $s->old_namesapce, $s->old_title );
424 $this->mTitle = $oldTitle;
425 $wgTitle = $oldTitle;
426 }
427 $this->mContent = Article::getRevisionText( $s );
428 $this->mUser = $s->old_user;
429 $this->mUserText = $s->old_user_text;
430 $this->mComment = $s->old_comment;
431 $this->mCounter = 0;
432 $this->mTimestamp = $s->old_timestamp;
433 }
434 $this->mContentLoaded = true;
435 return $this->mContent;
436 }
437
438 # Gets the article text without using so many damn globals
439 # Returns false on error
440 function getContentWithoutUsingSoManyDamnGlobals( $oldid = 0, $noredir = false ) {
441 global $wgMwRedir;
442
443 if ( $this->mContentLoaded ) {
444 return $this->mContent;
445 }
446 $this->mContent = false;
447
448 $fname = 'Article::getContentWithout';
449 $dbr =& wfGetDB( DB_SLAVE );
450
451 if ( ! $oldid ) { # Retrieve current version
452 $id = $this->getID();
453 if ( 0 == $id ) {
454 return false;
455 }
456
457 $s = $dbr->getArray( 'cur', $this->getCurContentFields(), array( 'cur_id' => $id ), $fname );
458 if ( $s === false ) {
459 return false;
460 }
461
462 # If we got a redirect, follow it (unless we've been told
463 # not to by either the function parameter or the query
464 if ( !$noredir && $wgMwRedir->matchStart( $s->cur_text ) ) {
465 if ( preg_match( '/\\[\\[([^\\]\\|]+)[\\]\\|]/',
466 $s->cur_text, $m ) ) {
467 $rt = Title::newFromText( $m[1] );
468 if( $rt && $rt->getInterwiki() == '' && $rt->getNamespace() != Namespace::getSpecial() ) {
469 $rid = $rt->getArticleID();
470 if ( 0 != $rid ) {
471 $redirRow = $dbr->getArray( 'cur', $this->getCurContentFields(), array( 'cur_id' => $rid ), $fname );
472
473 if ( $redirRow !== false ) {
474 $this->mRedirectedFrom = $this->mTitle->getPrefixedText();
475 $this->mTitle = $rt;
476 $s = $redirRow;
477 }
478 }
479 }
480 }
481 }
482
483 $this->mContent = $s->cur_text;
484 $this->mUser = $s->cur_user;
485 $this->mUserText = $s->cur_user_text;
486 $this->mComment = $s->cur_comment;
487 $this->mCounter = $s->cur_counter;
488 $this->mTimestamp = $s->cur_timestamp;
489 $this->mTouched = $s->cur_touched;
490 $this->mTitle->mRestrictions = explode( ",", trim( $s->cur_restrictions ) );
491 $this->mTitle->mRestrictionsLoaded = true;
492 } else { # oldid set, retrieve historical version
493 $s = $dbr->getArray( 'old', $this->getOldContentFields(), array( 'old_id' => $oldid ) );
494 if ( $s === false ) {
495 return false;
496 }
497 $this->mContent = Article::getRevisionText( $s );
498 $this->mUser = $s->old_user;
499 $this->mUserText = $s->old_user_text;
500 $this->mComment = $s->old_comment;
501 $this->mCounter = 0;
502 $this->mTimestamp = $s->old_timestamp;
503 }
504 $this->mContentLoaded = true;
505 return $this->mContent;
506 }
507
508 function getID() {
509 if( $this->mTitle ) {
510 return $this->mTitle->getArticleID();
511 } else {
512 return 0;
513 }
514 }
515
516 function getCount()
517 {
518 if ( -1 == $this->mCounter ) {
519 $id = $this->getID();
520 $dbr =& wfGetDB( DB_SLAVE );
521 $this->mCounter = $dbr->getField( 'cur', 'cur_counter', "cur_id={$id}" );
522 }
523 return $this->mCounter;
524 }
525
526 # Would the given text make this article a "good" article (i.e.,
527 # suitable for including in the article count)?
528
529 function isCountable( $text )
530 {
531 global $wgUseCommaCount, $wgMwRedir;
532
533 if ( 0 != $this->mTitle->getNamespace() ) { return 0; }
534 if ( $wgMwRedir->matchStart( $text ) ) { return 0; }
535 $token = ($wgUseCommaCount ? ',' : '[[' );
536 if ( false === strstr( $text, $token ) ) { return 0; }
537 return 1;
538 }
539
540 # Loads everything from cur except cur_text
541 # This isn't necessary for all uses, so it's only done if needed.
542
543 /* private */ function loadLastEdit()
544 {
545 global $wgOut;
546 if ( -1 != $this->mUser ) return;
547
548 $fname = 'Article::loadLastEdit';
549
550 $dbr =& wfGetDB( DB_SLAVE );
551 $s = $dbr->getArray( 'cur',
552 array( 'cur_user','cur_user_text','cur_timestamp', 'cur_comment','cur_minor_edit' ),
553 array( 'cur_id' => $this->getID() ), $fname );
554
555 if ( $s !== false ) {
556 $this->mUser = $s->cur_user;
557 $this->mUserText = $s->cur_user_text;
558 $this->mTimestamp = $s->cur_timestamp;
559 $this->mComment = $s->cur_comment;
560 $this->mMinorEdit = $s->cur_minor_edit;
561 }
562 }
563
564 function getTimestamp()
565 {
566 $this->loadLastEdit();
567 return $this->mTimestamp;
568 }
569
570 function getUser()
571 {
572 $this->loadLastEdit();
573 return $this->mUser;
574 }
575
576 function getUserText()
577 {
578 $this->loadLastEdit();
579 return $this->mUserText;
580 }
581
582 function getComment()
583 {
584 $this->loadLastEdit();
585 return $this->mComment;
586 }
587
588 function getMinorEdit()
589 {
590 $this->loadLastEdit();
591 return $this->mMinorEdit;
592 }
593
594 function getContributors($limit = 0, $offset = 0)
595 {
596 $fname = 'Article::getContributors';
597
598 # XXX: this is expensive; cache this info somewhere.
599
600 $title = $this->mTitle;
601 $contribs = array();
602 $dbr =& wfGetDB( DB_SLAVE );
603 $oldTable = $dbr->tableName( 'old' );
604 $userTable = $dbr->tableName( 'user' );
605 $encDBkey = $dbr->strencode( $title->getDBkey() );
606 $ns = $title->getNamespace();
607 $user = $this->getUser();
608
609 $sql = "SELECT old_user, old_user_text, user_real_name, MAX(old_timestamp) as timestamp
610 FROM $oldTable LEFT JOIN $userTable ON old_user = user_id
611 WHERE old_namespace = $user
612 AND old_title = $encDBkey
613 AND old_user != $user
614 GROUP BY old_user
615 ORDER BY timestamp DESC";
616
617 if ($limit > 0) {
618 $sql .= ' LIMIT '.$limit;
619 }
620
621 $res = $dbr->query($sql, $fname);
622
623 while ( $line = $dbr->fetchObject( $res ) ) {
624 $contribs[] = array($line->old_user, $line->old_user_text, $line->user_real_name);
625 }
626
627 $dbr->freeResult($res);
628
629 return $contribs;
630 }
631
632 # This is the default action of the script: just view the page of
633 # the given title.
634
635 function view()
636 {
637 global $wgUser, $wgOut, $wgLang, $wgRequest;
638 global $wgLinkCache, $IP, $wgEnableParserCache;
639
640 $fname = 'Article::view';
641 wfProfileIn( $fname );
642
643 # Get variables from query string :P
644 $oldid = $wgRequest->getVal( 'oldid' );
645 $diff = $wgRequest->getVal( 'diff' );
646
647 $wgOut->setArticleFlag( true );
648 $wgOut->setRobotpolicy( 'index,follow' );
649
650 # If we got diff and oldid in the query, we want to see a
651 # diff page instead of the article.
652
653 if ( !is_null( $diff ) ) {
654 $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
655 $de = new DifferenceEngine( intval($oldid), intval($diff) );
656 $de->showDiffPage();
657 wfProfileOut( $fname );
658 return;
659 }
660
661 if ( empty( $oldid ) && $this->checkTouched() ) {
662 if( $wgOut->checkLastModified( $this->mTouched ) ){
663 return;
664 } else if ( $this->tryFileCache() ) {
665 # tell wgOut that output is taken care of
666 $wgOut->disable();
667 $this->viewUpdates();
668 return;
669 }
670 }
671
672 # Should the parser cache be used?
673 if ( $wgEnableParserCache && intval($wgUser->getOption( 'stubthreshold' )) == 0 && empty( $oldid ) ) {
674 $pcache = true;
675 } else {
676 $pcache = false;
677 }
678
679 $outputDone = false;
680 if ( $pcache ) {
681 if ( $wgOut->tryParserCache( $this, $wgUser ) ) {
682 $outputDone = true;
683 }
684 }
685
686 if ( !$outputDone ) {
687 $text = $this->getContent( false ); # May change mTitle by following a redirect
688
689 # Another whitelist check in case oldid or redirects are altering the title
690 if ( !$this->mTitle->userCanRead() ) {
691 $wgOut->loginToUse();
692 $wgOut->output();
693 exit;
694 }
695
696
697 # We're looking at an old revision
698
699 if ( !empty( $oldid ) ) {
700 $this->setOldSubtitle();
701 $wgOut->setRobotpolicy( 'noindex,follow' );
702 }
703 if ( '' != $this->mRedirectedFrom ) {
704 $sk = $wgUser->getSkin();
705 $redir = $sk->makeKnownLink( $this->mRedirectedFrom, '',
706 'redirect=no' );
707 $s = wfMsg( 'redirectedfrom', $redir );
708 $wgOut->setSubtitle( $s );
709
710 # Can't cache redirects
711 $pcache = false;
712 }
713
714 # wrap user css and user js in pre and don't parse
715 # XXX: use $this->mTitle->usCssJsSubpage() when php is fixed/ a workaround is found
716 if (
717 $this->mTitle->getNamespace() == Namespace::getUser() &&
718 preg_match('/\\/[\\w]+\\.(css|js)$/', $this->mTitle->getDBkey())
719 ) {
720 $wgOut->addWikiText( wfMsg('clearyourcache'));
721 $wgOut->addHTML( '<pre>'.htmlspecialchars($this->mContent)."\n</pre>" );
722 } else if ( $pcache ) {
723 $wgOut->addWikiText( $text, true, $this );
724 } else {
725 $wgOut->addWikiText( $text );
726 }
727 }
728 $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
729
730 # Add link titles as META keywords
731 $wgOut->addMetaTags() ;
732
733 $this->viewUpdates();
734 wfProfileOut( $fname );
735 }
736
737 # Theoretically we could defer these whole insert and update
738 # functions for after display, but that's taking a big leap
739 # of faith, and we want to be able to report database
740 # errors at some point.
741
742 /* private */ function insertNewArticle( $text, $summary, $isminor, $watchthis )
743 {
744 global $wgOut, $wgUser, $wgMwRedir;
745 global $wgUseSquid, $wgDeferredUpdateList, $wgInternalServer;
746
747 $fname = 'Article::insertNewArticle';
748
749 $this->mCountAdjustment = $this->isCountable( $text );
750
751 $ns = $this->mTitle->getNamespace();
752 $ttl = $this->mTitle->getDBkey();
753 $text = $this->preSaveTransform( $text );
754 if ( $wgMwRedir->matchStart( $text ) ) { $redir = 1; }
755 else { $redir = 0; }
756
757 $now = wfTimestampNow();
758 $won = wfInvertTimestamp( $now );
759 wfSeedRandom();
760 $rand = number_format( mt_rand() / mt_getrandmax(), 12, '.', '' );
761 $dbw =& wfGetDB( DB_MASTER );
762
763 $cur_id = $dbw->nextSequenceValue( 'cur_cur_id_seq' );
764
765 $isminor = ( $isminor && $wgUser->getID() ) ? 1 : 0;
766
767 $dbw->insertArray( 'cur', array(
768 'cur_id' => $cur_id,
769 'cur_namespace' => $ns,
770 'cur_title' => $ttl,
771 'cur_text' => $text,
772 'cur_comment' => $summary,
773 'cur_user' => $wgUser->getID(),
774 'cur_timestamp' => $now,
775 'cur_minor_edit' => $isminor,
776 'cur_counter' => 0,
777 'cur_restrictions' => '',
778 'cur_user_text' => $wgUser->getName(),
779 'cur_is_redirect' => $redir,
780 'cur_is_new' => 1,
781 'cur_random' => $rand,
782 'cur_touched' => $now,
783 'inverse_timestamp' => $won,
784 ), $fname );
785
786 $newid = $dbw->insertId();
787 $this->mTitle->resetArticleID( $newid );
788
789 Article::onArticleCreate( $this->mTitle );
790 RecentChange::notifyNew( $now, $this->mTitle, $isminor, $wgUser, $summary );
791
792 if ($watchthis) {
793 if(!$this->mTitle->userIsWatching()) $this->watch();
794 } else {
795 if ( $this->mTitle->userIsWatching() ) {
796 $this->unwatch();
797 }
798 }
799
800 # The talk page isn't in the regular link tables, so we need to update manually:
801 $talkns = $ns ^ 1; # talk -> normal; normal -> talk
802 $dbw->updateArray( 'cur', array( 'cur_touched' => $now ), array( 'cur_namespace' => $talkns, 'cur_title' => $ttl ), $fname );
803
804 # standard deferred updates
805 $this->editUpdates( $text );
806
807 $this->showArticle( $text, wfMsg( 'newarticle' ) );
808 }
809
810
811 /* Side effects: loads last edit */
812 function getTextOfLastEditWithSectionReplacedOrAdded($section, $text, $summary = ''){
813 $this->loadLastEdit();
814 $oldtext = $this->getContent( true );
815 if ($section != '') {
816 if($section=='new') {
817 if($summary) $subject="== {$summary} ==\n\n";
818 $text=$oldtext."\n\n".$subject.$text;
819 } else {
820
821 # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
822 # comments to be stripped as well)
823 $striparray=array();
824 $parser=new Parser();
825 $parser->mOutputType=OT_WIKI;
826 $oldtext=$parser->strip($oldtext, $striparray, true);
827
828 # now that we can be sure that no pseudo-sections are in the source,
829 # split it up
830 # Unfortunately we can't simply do a preg_replace because that might
831 # replace the wrong section, so we have to use the section counter instead
832 $secs=preg_split('/(^=+.*?=+|^<h[1-6].*?' . '>.*?<\/h[1-6].*?' . '>)/mi',
833 $oldtext,-1,PREG_SPLIT_DELIM_CAPTURE);
834 $secs[$section*2]=$text."\n\n"; // replace with edited
835
836 # section 0 is top (intro) section
837 if($section!=0) {
838
839 # headline of old section - we need to go through this section
840 # to determine if there are any subsections that now need to
841 # be erased, as the mother section has been replaced with
842 # the text of all subsections.
843 $headline=$secs[$section*2-1];
844 preg_match( '/^(=+).*?=+|^<h([1-6]).*?' . '>.*?<\/h[1-6].*?' . '>/mi',$headline,$matches);
845 $hlevel=$matches[1];
846
847 # determine headline level for wikimarkup headings
848 if(strpos($hlevel,'=')!==false) {
849 $hlevel=strlen($hlevel);
850 }
851
852 $secs[$section*2-1]=''; // erase old headline
853 $count=$section+1;
854 $break=false;
855 while(!empty($secs[$count*2-1]) && !$break) {
856
857 $subheadline=$secs[$count*2-1];
858 preg_match(
859 '/^(=+).*?=+|^<h([1-6]).*?' . '>.*?<\/h[1-6].*?' . '>/mi',$subheadline,$matches);
860 $subhlevel=$matches[1];
861 if(strpos($subhlevel,'=')!==false) {
862 $subhlevel=strlen($subhlevel);
863 }
864 if($subhlevel > $hlevel) {
865 // erase old subsections
866 $secs[$count*2-1]='';
867 $secs[$count*2]='';
868 }
869 if($subhlevel <= $hlevel) {
870 $break=true;
871 }
872 $count++;
873
874 }
875
876 }
877 $text=join('',$secs);
878 # reinsert the stuff that we stripped out earlier
879 $text=$parser->unstrip($text,$striparray);
880 $text=$parser->unstripNoWiki($text,$striparray);
881 }
882
883 }
884 return $text;
885 }
886
887 function updateArticle( $text, $summary, $minor, $watchthis, $forceBot = false, $sectionanchor = '' )
888 {
889 global $wgOut, $wgUser;
890 global $wgDBtransactions, $wgMwRedir;
891 global $wgUseSquid, $wgInternalServer;
892
893 $fname = 'Article::updateArticle';
894 $good = true;
895
896 if ( $this->mMinorEdit ) { $me1 = 1; } else { $me1 = 0; }
897 if ( $minor && $wgUser->getID() ) { $me2 = 1; } else { $me2 = 0; }
898 if ( preg_match( "/^((" . $wgMwRedir->getBaseRegex() . ')[^\\n]+)/i', $text, $m ) ) {
899 $redir = 1;
900 $text = $m[1] . "\n"; # Remove all content but redirect
901 }
902 else { $redir = 0; }
903
904 $text = $this->preSaveTransform( $text );
905 $dbw =& wfGetDB( DB_MASTER );
906
907 # Update article, but only if changed.
908
909 # It's important that we either rollback or complete, otherwise an attacker could
910 # overwrite cur entries by sending precisely timed user aborts. Random bored users
911 # could conceivably have the same effect, especially if cur is locked for long periods.
912 if( $wgDBtransactions ) {
913 $dbw->query( 'BEGIN', $fname );
914 } else {
915 $userAbort = ignore_user_abort( true );
916 }
917
918 $oldtext = $this->getContent( true );
919
920 if ( 0 != strcmp( $text, $oldtext ) ) {
921 $this->mCountAdjustment = $this->isCountable( $text )
922 - $this->isCountable( $oldtext );
923 $now = wfTimestampNow();
924 $won = wfInvertTimestamp( $now );
925
926 # First update the cur row
927 $dbw->updateArray( 'cur',
928 array( /* SET */
929 'cur_text' => $text,
930 'cur_comment' => $summary,
931 'cur_minor_edit' => $me2,
932 'cur_user' => $wgUser->getID(),
933 'cur_timestamp' => $now,
934 'cur_user_text' => $wgUser->getName(),
935 'cur_is_redirect' => $redir,
936 'cur_is_new' => 0,
937 'cur_touched' => $now,
938 'inverse_timestamp' => $won
939 ), array( /* WHERE */
940 'cur_id' => $this->getID(),
941 'cur_timestamp' => $this->getTimestamp()
942 ), $fname
943 );
944
945 if( $dbw->affectedRows() == 0 ) {
946 /* Belated edit conflict! Run away!! */
947 $good = false;
948 } else {
949 # Now insert the previous revision into old
950
951 # This overwrites $oldtext if revision compression is on
952 $flags = Article::compressRevisionText( $oldtext );
953
954 $dbw->insertArray( 'old',
955 array(
956 'old_id' => $dbw->nextSequenceValue( 'old_old_id_seq' ),
957 'old_namespace' => $this->mTitle->getNamespace(),
958 'old_title' => $this->mTitle->getDBkey(),
959 'old_text' => $oldtext,
960 'old_comment' => $this->getComment(),
961 'old_user' => $this->getUser(),
962 'old_user_text' => $this->getUserText(),
963 'old_timestamp' => $this->getTimestamp(),
964 'old_minor_edit' => $me1,
965 'inverse_timestamp' => wfInvertTimestamp( $this->getTimestamp() ),
966 'old_flags' => $flags,
967 ), $fname
968 );
969
970 $oldid = $dbw->insertId();
971
972 $bot = (int)($wgUser->isBot() || $forceBot);
973 RecentChange::notifyEdit( $now, $this->mTitle, $me2, $wgUser, $summary,
974 $oldid, $this->getTimestamp(), $bot );
975 Article::onArticleEdit( $this->mTitle );
976 }
977 }
978
979 if( $wgDBtransactions ) {
980 $dbw->query( 'COMMIT', $fname );
981 } else {
982 ignore_user_abort( $userAbort );
983 }
984
985 if ( $good ) {
986 if ($watchthis) {
987 if (!$this->mTitle->userIsWatching()) $this->watch();
988 } else {
989 if ( $this->mTitle->userIsWatching() ) {
990 $this->unwatch();
991 }
992 }
993 # standard deferred updates
994 $this->editUpdates( $text );
995
996
997 $urls = array();
998 # Template namespace
999 # Purge all articles linking here
1000 if ( $this->mTitle->getNamespace() == NS_TEMPLATE) {
1001 $titles = $this->mTitle->getLinksTo();
1002 Title::touchArray( $titles );
1003 if ( $wgUseSquid ) {
1004 foreach ( $titles as $title ) {
1005 $urls[] = $title->getInternalURL();
1006 }
1007 }
1008 }
1009
1010 # Squid updates
1011 if ( $wgUseSquid ) {
1012 $urls = array_merge( $urls, $this->mTitle->getSquidURLs() );
1013 $u = new SquidUpdate( $urls );
1014 $u->doUpdate();
1015 }
1016
1017 $this->showArticle( $text, wfMsg( 'updated' ), $sectionanchor );
1018 }
1019 return $good;
1020 }
1021
1022 # After we've either updated or inserted the article, update
1023 # the link tables and redirect to the new page.
1024
1025 function showArticle( $text, $subtitle , $sectionanchor = '' )
1026 {
1027 global $wgOut, $wgUser, $wgLinkCache;
1028 global $wgMwRedir;
1029
1030 $wgLinkCache = new LinkCache();
1031 # Select for update
1032 $wgLinkCache->forUpdate( true );
1033
1034 # Get old version of link table to allow incremental link updates
1035 $wgLinkCache->preFill( $this->mTitle );
1036 $wgLinkCache->clear();
1037
1038 # Switch on use of link cache in the skin
1039 $sk =& $wgUser->getSkin();
1040 $sk->postParseLinkColour( false );
1041
1042 # Now update the link cache by parsing the text
1043 $wgOut = new OutputPage();
1044 $wgOut->addWikiText( $text );
1045
1046 if( $wgMwRedir->matchStart( $text ) )
1047 $r = 'redirect=no';
1048 else
1049 $r = '';
1050 $wgOut->redirect( $this->mTitle->getFullURL( $r ).$sectionanchor );
1051 }
1052
1053 # Validate article
1054
1055 function validate ()
1056 {
1057 global $wgOut ;
1058 $v = new Validation ;
1059 $html = $v->validate_form ( $this->mTitle->getDBkey() ) ;
1060 $wgOut->setPagetitle( wfMsg( 'validate' ) . " : " . $this->mTitle->getText() );
1061 $wgOut->setRobotpolicy( 'noindex,follow' );
1062 $wgOut->addHTML( $html ) ;
1063 }
1064
1065 # Add this page to my watchlist
1066
1067 function watch( $add = true )
1068 {
1069 global $wgUser, $wgOut, $wgLang;
1070 global $wgDeferredUpdateList;
1071
1072 if ( 0 == $wgUser->getID() ) {
1073 $wgOut->errorpage( 'watchnologin', 'watchnologintext' );
1074 return;
1075 }
1076 if ( wfReadOnly() ) {
1077 $wgOut->readOnlyPage();
1078 return;
1079 }
1080 if( $add )
1081 $wgUser->addWatch( $this->mTitle );
1082 else
1083 $wgUser->removeWatch( $this->mTitle );
1084
1085 $wgOut->setPagetitle( wfMsg( $add ? 'addedwatch' : 'removedwatch' ) );
1086 $wgOut->setRobotpolicy( 'noindex,follow' );
1087
1088 $sk = $wgUser->getSkin() ;
1089 $link = $this->mTitle->getPrefixedText();
1090
1091 if($add)
1092 $text = wfMsg( 'addedwatchtext', $link );
1093 else
1094 $text = wfMsg( 'removedwatchtext', $link );
1095 $wgOut->addWikiText( $text );
1096
1097 $up = new UserUpdate();
1098 array_push( $wgDeferredUpdateList, $up );
1099
1100 $wgOut->returnToMain( false );
1101 }
1102
1103 function unwatch()
1104 {
1105 $this->watch( false );
1106 }
1107
1108 function protect( $limit = 'sysop' )
1109 {
1110 global $wgUser, $wgOut, $wgRequest;
1111
1112 if ( ! $wgUser->isSysop() ) {
1113 $wgOut->sysopRequired();
1114 return;
1115 }
1116 if ( wfReadOnly() ) {
1117 $wgOut->readOnlyPage();
1118 return;
1119 }
1120 $id = $this->mTitle->getArticleID();
1121 if ( 0 == $id ) {
1122 $wgOut->fatalError( wfMsg( 'badarticleerror' ) );
1123 return;
1124 }
1125
1126 $confirm = $wgRequest->getBool( 'wpConfirmProtect' ) && $wgRequest->wasPosted();
1127 $reason = $wgRequest->getText( 'wpReasonProtect' );
1128
1129 if ( $confirm ) {
1130 $dbw =& wfGetDB( DB_MASTER );
1131 $dbw->updateArray( 'cur',
1132 array( /* SET */
1133 'cur_touched' => wfTimestampNow(),
1134 'cur_restrictions' => (string)$limit
1135 ), array( /* WHERE */
1136 'cur_id' => $id
1137 ), 'Article::protect'
1138 );
1139
1140 $log = new LogPage( wfMsg( 'protectlogpage' ), wfMsg( 'protectlogtext' ) );
1141 if ( $limit === "" ) {
1142 $log->addEntry( wfMsg( 'unprotectedarticle', $this->mTitle->getPrefixedText() ), $reason );
1143 } else {
1144 $log->addEntry( wfMsg( 'protectedarticle', $this->mTitle->getPrefixedText() ), $reason );
1145 }
1146 $wgOut->redirect( $this->mTitle->getFullURL() );
1147 return;
1148 } else {
1149 $reason = htmlspecialchars( wfMsg( 'protectreason' ) );
1150 return $this->confirmProtect( '', $reason, $limit );
1151 }
1152 }
1153
1154 # Output protection confirmation dialog
1155 function confirmProtect( $par, $reason, $limit = 'sysop' )
1156 {
1157 global $wgOut;
1158
1159 wfDebug( "Article::confirmProtect\n" );
1160
1161 $sub = htmlspecialchars( $this->mTitle->getPrefixedText() );
1162 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1163
1164 $check = '';
1165 $protcom = '';
1166
1167 if ( $limit === '' ) {
1168 $wgOut->setPageTitle( wfMsg( 'confirmunprotect' ) );
1169 $wgOut->setSubtitle( wfMsg( 'unprotectsub', $sub ) );
1170 $wgOut->addWikiText( wfMsg( 'confirmunprotecttext' ) );
1171 $check = htmlspecialchars( wfMsg( 'confirmunprotect' ) );
1172 $protcom = htmlspecialchars( wfMsg( 'unprotectcomment' ) );
1173 $formaction = $this->mTitle->escapeLocalURL( 'action=unprotect' . $par );
1174 } else {
1175 $wgOut->setPageTitle( wfMsg( 'confirmprotect' ) );
1176 $wgOut->setSubtitle( wfMsg( 'protectsub', $sub ) );
1177 $wgOut->addWikiText( wfMsg( 'confirmprotecttext' ) );
1178 $check = htmlspecialchars( wfMsg( 'confirmprotect' ) );
1179 $protcom = htmlspecialchars( wfMsg( 'protectcomment' ) );
1180 $formaction = $this->mTitle->escapeLocalURL( 'action=protect' . $par );
1181 }
1182
1183 $confirm = htmlspecialchars( wfMsg( 'confirm' ) );
1184
1185 $wgOut->addHTML( "
1186 <form id='protectconfirm' method='post' action=\"{$formaction}\">
1187 <table border='0'>
1188 <tr>
1189 <td align='right'>
1190 <label for='wpReasonProtect'>{$protcom}:</label>
1191 </td>
1192 <td align='left'>
1193 <input type='text' size='60' name='wpReasonProtect' id='wpReasonProtect' value=\"" . htmlspecialchars( $reason ) . "\" />
1194 </td>
1195 </tr>
1196 <tr>
1197 <td>&nbsp;</td>
1198 </tr>
1199 <tr>
1200 <td align='right'>
1201 <input type='checkbox' name='wpConfirmProtect' value='1' id='wpConfirmProtect' />
1202 </td>
1203 <td>
1204 <label for='wpConfirmProtect'>{$check}</label>
1205 </td>
1206 </tr>
1207 <tr>
1208 <td>&nbsp;</td>
1209 <td>
1210 <input type='submit' name='wpConfirmProtectB' value=\"{$confirm}\" />
1211 </td>
1212 </tr>
1213 </table>
1214 </form>\n" );
1215
1216 $wgOut->returnToMain( false );
1217 }
1218
1219 function unprotect()
1220 {
1221 return $this->protect( '' );
1222 }
1223
1224 # UI entry point for page deletion
1225 function delete()
1226 {
1227 global $wgUser, $wgOut, $wgMessageCache, $wgRequest;
1228 $fname = 'Article::delete';
1229 $confirm = $wgRequest->getBool( 'wpConfirm' ) && $wgRequest->wasPosted();
1230 $reason = $wgRequest->getText( 'wpReason' );
1231
1232 # This code desperately needs to be totally rewritten
1233
1234 # Check permissions
1235 if ( ( ! $wgUser->isSysop() ) ) {
1236 $wgOut->sysopRequired();
1237 return;
1238 }
1239 if ( wfReadOnly() ) {
1240 $wgOut->readOnlyPage();
1241 return;
1242 }
1243
1244 # Better double-check that it hasn't been deleted yet!
1245 $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
1246 if ( ( '' == trim( $this->mTitle->getText() ) )
1247 or ( $this->mTitle->getArticleId() == 0 ) ) {
1248 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
1249 return;
1250 }
1251
1252 if ( $confirm ) {
1253 $this->doDelete( $reason );
1254 return;
1255 }
1256
1257 # determine whether this page has earlier revisions
1258 # and insert a warning if it does
1259 # we select the text because it might be useful below
1260 $dbr =& wfGetDB( DB_SLAVE );
1261 $ns = $this->mTitle->getNamespace();
1262 $title = $this->mTitle->getDBkey();
1263 $old = $dbr->getArray( 'old',
1264 array( 'old_text', 'old_flags' ),
1265 array(
1266 'old_namespace' => $ns,
1267 'old_title' => $title,
1268 ), $fname, array( 'ORDER BY' => 'inverse_timestamp' )
1269 );
1270
1271 if( $old !== false && !$confirm ) {
1272 $skin=$wgUser->getSkin();
1273 $wgOut->addHTML('<b>'.wfMsg('historywarning'));
1274 $wgOut->addHTML( $skin->historyLink() .'</b>');
1275 }
1276
1277 # Fetch cur_text
1278 $s = $dbr->getArray( 'cur',
1279 array( 'cur_text' ),
1280 array(
1281 'cur_namespace' => $ns,
1282 'cur_title' => $title,
1283 ), $fname
1284 );
1285
1286 if( $s !== false ) {
1287 # if this is a mini-text, we can paste part of it into the deletion reason
1288
1289 #if this is empty, an earlier revision may contain "useful" text
1290 $blanked = false;
1291 if($s->cur_text!="") {
1292 $text=$s->cur_text;
1293 } else {
1294 if($old) {
1295 $text = Article::getRevisionText( $old );
1296 $blanked = true;
1297 }
1298
1299 }
1300
1301 $length=strlen($text);
1302
1303 # this should not happen, since it is not possible to store an empty, new
1304 # page. Let's insert a standard text in case it does, though
1305 if($length == 0 && $reason === '') {
1306 $reason = wfMsg('exblank');
1307 }
1308
1309 if($length < 500 && $reason === '') {
1310
1311 # comment field=255, let's grep the first 150 to have some user
1312 # space left
1313 $text=substr($text,0,150);
1314 # let's strip out newlines and HTML tags
1315 $text=preg_replace('/\"/',"'",$text);
1316 $text=preg_replace('/\</','&lt;',$text);
1317 $text=preg_replace('/\>/','&gt;',$text);
1318 $text=preg_replace("/[\n\r]/",'',$text);
1319 if(!$blanked) {
1320 $reason=wfMsg('excontent'). " '".$text;
1321 } else {
1322 $reason=wfMsg('exbeforeblank') . " '".$text;
1323 }
1324 if($length>150) { $reason .= '...'; } # we've only pasted part of the text
1325 $reason.="'";
1326 }
1327 }
1328
1329 return $this->confirmDelete( '', $reason );
1330 }
1331
1332 # Output deletion confirmation dialog
1333 function confirmDelete( $par, $reason )
1334 {
1335 global $wgOut;
1336
1337 wfDebug( "Article::confirmDelete\n" );
1338
1339 $sub = htmlspecialchars( $this->mTitle->getPrefixedText() );
1340 $wgOut->setSubtitle( wfMsg( 'deletesub', $sub ) );
1341 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1342 $wgOut->addWikiText( wfMsg( 'confirmdeletetext' ) );
1343
1344 $formaction = $this->mTitle->escapeLocalURL( 'action=delete' . $par );
1345
1346 $confirm = htmlspecialchars( wfMsg( 'confirm' ) );
1347 $check = htmlspecialchars( wfMsg( 'confirmcheck' ) );
1348 $delcom = htmlspecialchars( wfMsg( 'deletecomment' ) );
1349
1350 $wgOut->addHTML( "
1351 <form id='deleteconfirm' method='post' action=\"{$formaction}\">
1352 <table border='0'>
1353 <tr>
1354 <td align='right'>
1355 <label for='wpReason'>{$delcom}:</label>
1356 </td>
1357 <td align='left'>
1358 <input type='text' size='60' name='wpReason' id='wpReason' value=\"" . htmlspecialchars( $reason ) . "\" />
1359 </td>
1360 </tr>
1361 <tr>
1362 <td>&nbsp;</td>
1363 </tr>
1364 <tr>
1365 <td align='right'>
1366 <input type='checkbox' name='wpConfirm' value='1' id='wpConfirm' />
1367 </td>
1368 <td>
1369 <label for='wpConfirm'>{$check}</label>
1370 </td>
1371 </tr>
1372 <tr>
1373 <td>&nbsp;</td>
1374 <td>
1375 <input type='submit' name='wpConfirmB' value=\"{$confirm}\" />
1376 </td>
1377 </tr>
1378 </table>
1379 </form>\n" );
1380
1381 $wgOut->returnToMain( false );
1382 }
1383
1384 # Perform a deletion and output success or failure messages
1385 function doDelete( $reason )
1386 {
1387 global $wgOut, $wgUser, $wgLang;
1388 $fname = 'Article::doDelete';
1389 wfDebug( "$fname\n" );
1390
1391 if ( $this->doDeleteArticle( $reason ) ) {
1392 $deleted = $this->mTitle->getPrefixedText();
1393
1394 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
1395 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1396
1397 $sk = $wgUser->getSkin();
1398 $loglink = $sk->makeKnownLink( $wgLang->getNsText(
1399 Namespace::getWikipedia() ) .
1400 ':' . wfMsg( 'dellogpage' ), wfMsg( 'deletionlog' ) );
1401
1402 $text = wfMsg( "deletedtext", $deleted, $loglink );
1403
1404 $wgOut->addHTML( '<p>' . $text . "</p>\n" );
1405 $wgOut->returnToMain( false );
1406 } else {
1407 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
1408 }
1409 }
1410
1411 # Back-end article deletion
1412 # Deletes the article with database consistency, writes logs, purges caches
1413 # Returns success
1414 function doDeleteArticle( $reason )
1415 {
1416 global $wgUser, $wgLang;
1417 global $wgUseSquid, $wgDeferredUpdateList, $wgInternalServer;
1418
1419 $fname = 'Article::doDeleteArticle';
1420 wfDebug( $fname."\n" );
1421
1422 $dbw =& wfGetDB( DB_MASTER );
1423 $ns = $this->mTitle->getNamespace();
1424 $t = $this->mTitle->getDBkey();
1425 $id = $this->mTitle->getArticleID();
1426
1427 if ( '' == $t || $id == 0 ) {
1428 return false;
1429 }
1430
1431 $u = new SiteStatsUpdate( 0, 1, -$this->isCountable( $this->getContent( true ) ) );
1432 array_push( $wgDeferredUpdateList, $u );
1433
1434 $linksTo = $this->mTitle->getLinksTo();
1435
1436 # Squid purging
1437 if ( $wgUseSquid ) {
1438 $urls = array(
1439 $this->mTitle->getInternalURL(),
1440 $this->mTitle->getInternalURL( 'history' )
1441 );
1442 foreach ( $linksTo as $linkTo ) {
1443 $urls[] = $linkTo->getInternalURL();
1444 }
1445
1446 $u = new SquidUpdate( $urls );
1447 array_push( $wgDeferredUpdateList, $u );
1448
1449 }
1450
1451 # Client and file cache invalidation
1452 Title::touchArray( $linksTo );
1453
1454 # Move article and history to the "archive" table
1455 $archiveTable = $dbw->tableName( 'archive' );
1456 $oldTable = $dbw->tableName( 'old' );
1457 $curTable = $dbw->tableName( 'cur' );
1458 $recentchangesTable = $dbw->tableName( 'recentchanges' );
1459 $linksTable = $dbw->tableName( 'links' );
1460 $brokenlinksTable = $dbw->tableName( 'brokenlinks' );
1461
1462 $dbw->insertSelect( 'archive', 'cur',
1463 array(
1464 'ar_namespace' => 'cur_namespace',
1465 'ar_title' => 'cur_title',
1466 'ar_text' => 'cur_text',
1467 'ar_comment' => 'cur_comment',
1468 'ar_user' => 'cur_user',
1469 'ar_user_text' => 'cur_user_text',
1470 'ar_timestamp' => 'cur_timestamp',
1471 'ar_minor_edit' => 'cur_minor_edit',
1472 'ar_flags' => 0,
1473 ), array(
1474 'cur_namespace' => $ns,
1475 'cur_title' => $t,
1476 ), $fname
1477 );
1478
1479 $dbw->insertSelect( 'archive', 'old',
1480 array(
1481 'ar_namespace' => 'old_namespace',
1482 'ar_title' => 'old_title',
1483 'ar_text' => 'old_text',
1484 'ar_comment' => 'old_comment',
1485 'ar_user' => 'old_user',
1486 'ar_user_text' => 'old_user_text',
1487 'ar_timestamp' => 'old_timestamp',
1488 'ar_minor_edit' => 'old_minor_edit',
1489 'ar_flags' => 'old_flags'
1490 ), array(
1491 'old_namespace' => $ns,
1492 'old_title' => $t,
1493 ), $fname
1494 );
1495
1496 # Now that it's safely backed up, delete it
1497
1498 $dbw->delete( 'cur', array( 'cur_namespace' => $ns, 'cur_title' => $t ), $fname );
1499 $dbw->delete( 'old', array( 'old_namespace' => $ns, 'old_title' => $t ), $fname );
1500 $dbw->delete( 'recentchanges', array( 'rc_namespace' => $ns, 'rc_title' => $t ), $fname );
1501
1502 # Finally, clean up the link tables
1503 $t = $this->mTitle->getPrefixedDBkey();
1504
1505 Article::onArticleDelete( $this->mTitle );
1506
1507 # Insert broken links
1508 $brokenLinks = array();
1509 foreach ( $linksTo as $titleObj ) {
1510 # Get article ID. Efficient because it was loaded into the cache by getLinksTo().
1511 $linkID = $titleObj->getArticleID();
1512 $brokenLinks[] = array( 'bl_from' => $linkID, 'bl_to' => $t );
1513 }
1514 $dbw->insert( 'brokenlinks', $brokenLinks, $fname, 'IGNORE' );
1515
1516 # Delete live links
1517 $dbw->delete( 'links', array( 'l_to' => $id ) );
1518 $dbw->delete( 'links', array( 'l_from' => $id ) );
1519 $dbw->delete( 'imagelinks', array( 'il_from' => $id ) );
1520 $dbw->delete( 'brokenlinks', array( 'bl_from' => $id ) );
1521 $dbw->delete( 'categorylinks', array( 'cl_from' => $id ) );
1522
1523 # Log the deletion
1524 $log = new LogPage( wfMsg( 'dellogpage' ), wfMsg( 'dellogpagetext' ) );
1525 $art = $this->mTitle->getPrefixedText();
1526 $log->addEntry( wfMsg( 'deletedarticle', $art ), $reason );
1527
1528 # Clear the cached article id so the interface doesn't act like we exist
1529 $this->mTitle->resetArticleID( 0 );
1530 $this->mTitle->mArticleID = 0;
1531 return true;
1532 }
1533
1534 function rollback()
1535 {
1536 global $wgUser, $wgLang, $wgOut, $wgRequest;
1537 $fname = "Article::rollback";
1538
1539 if ( ! $wgUser->isSysop() ) {
1540 $wgOut->sysopRequired();
1541 return;
1542 }
1543 if ( wfReadOnly() ) {
1544 $wgOut->readOnlyPage( $this->getContent( true ) );
1545 return;
1546 }
1547 $dbw =& wfGetDB( DB_MASTER );
1548
1549 # Enhanced rollback, marks edits rc_bot=1
1550 $bot = $wgRequest->getBool( 'bot' );
1551
1552 # Replace all this user's current edits with the next one down
1553 $tt = $this->mTitle->getDBKey();
1554 $n = $this->mTitle->getNamespace();
1555
1556 # Get the last editor, lock table exclusively
1557 $s = $dbw->getArray( 'cur',
1558 array( 'cur_id','cur_user','cur_user_text','cur_comment' ),
1559 array( 'cur_title' => $tt, 'cur_namespace' => $n ),
1560 $fname, 'FOR UPDATE'
1561 );
1562 if( $s === false ) {
1563 # Something wrong
1564 $wgOut->addHTML( wfMsg( 'notanarticle' ) );
1565 return;
1566 }
1567 $ut = $dbw->strencode( $s->cur_user_text );
1568 $uid = $s->cur_user;
1569 $pid = $s->cur_id;
1570
1571 $from = str_replace( '_', ' ', $wgRequest->getVal( 'from' ) );
1572 if( $from != $s->cur_user_text ) {
1573 $wgOut->setPageTitle(wfmsg('rollbackfailed'));
1574 $wgOut->addWikiText( wfMsg( 'alreadyrolled',
1575 htmlspecialchars( $this->mTitle->getPrefixedText()),
1576 htmlspecialchars( $from ),
1577 htmlspecialchars( $s->cur_user_text ) ) );
1578 if($s->cur_comment != '') {
1579 $wgOut->addHTML(
1580 wfMsg('editcomment',
1581 htmlspecialchars( $s->cur_comment ) ) );
1582 }
1583 return;
1584 }
1585
1586 # Get the last edit not by this guy
1587 $s = $dbw->getArray( 'old',
1588 array( 'old_text','old_user','old_user_text','old_timestamp','old_flags' ),
1589 array(
1590 'old_namespace' => $n,
1591 'old_title' => $tt,
1592 "old_user <> {$uid} OR old_user_text <> '{$ut}'"
1593 ), $fname, array( 'FOR UPDATE', 'USE INDEX' => 'name_title_timestamp' )
1594 );
1595 if( $s === false ) {
1596 # Something wrong
1597 $wgOut->setPageTitle(wfMsg('rollbackfailed'));
1598 $wgOut->addHTML( wfMsg( 'cantrollback' ) );
1599 return;
1600 }
1601
1602 if ( $bot ) {
1603 # Mark all reverted edits as bot
1604 $dbw->updateArray( 'recentchanges',
1605 array( /* SET */
1606 'rc_bot' => 1
1607 ), array( /* WHERE */
1608 'rc_user' => $uid,
1609 "rc_timestamp > '{$s->old_timestamp}'",
1610 ), $fname
1611 );
1612 }
1613
1614 # Save it!
1615 $newcomment = wfMsg( 'revertpage', $s->old_user_text, $from );
1616 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
1617 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1618 $wgOut->addHTML( '<h2>' . $newcomment . "</h2>\n<hr />\n" );
1619 $this->updateArticle( Article::getRevisionText( $s ), $newcomment, 1, $this->mTitle->userIsWatching(), $bot );
1620 Article::onArticleEdit( $this->mTitle );
1621 $wgOut->returnToMain( false );
1622 }
1623
1624
1625 # Do standard deferred updates after page view
1626
1627 /* private */ function viewUpdates()
1628 {
1629 global $wgDeferredUpdateList;
1630 if ( 0 != $this->getID() ) {
1631 global $wgDisableCounters;
1632 if( !$wgDisableCounters ) {
1633 Article::incViewCount( $this->getID() );
1634 $u = new SiteStatsUpdate( 1, 0, 0 );
1635 array_push( $wgDeferredUpdateList, $u );
1636 }
1637 $u = new UserTalkUpdate( 0, $this->mTitle->getNamespace(),
1638 $this->mTitle->getDBkey() );
1639 array_push( $wgDeferredUpdateList, $u );
1640 }
1641 }
1642
1643 # Do standard deferred updates after page edit.
1644 # Every 1000th edit, prune the recent changes table.
1645
1646 /* private */ function editUpdates( $text )
1647 {
1648 global $wgDeferredUpdateList, $wgDBname, $wgMemc;
1649 global $wgMessageCache;
1650
1651 wfSeedRandom();
1652 if ( 0 == mt_rand( 0, 999 ) ) {
1653 $dbw =& wfGetDB( DB_MASTER );
1654 $cutoff = wfUnix2Timestamp( time() - ( 7 * 86400 ) );
1655 $sql = "DELETE FROM recentchanges WHERE rc_timestamp < '{$cutoff}'";
1656 $dbw->query( $sql );
1657 }
1658 $id = $this->getID();
1659 $title = $this->mTitle->getPrefixedDBkey();
1660 $shortTitle = $this->mTitle->getDBkey();
1661
1662 $adj = $this->mCountAdjustment;
1663
1664 if ( 0 != $id ) {
1665 $u = new LinksUpdate( $id, $title );
1666 array_push( $wgDeferredUpdateList, $u );
1667 $u = new SiteStatsUpdate( 0, 1, $adj );
1668 array_push( $wgDeferredUpdateList, $u );
1669 $u = new SearchUpdate( $id, $title, $text );
1670 array_push( $wgDeferredUpdateList, $u );
1671
1672 $u = new UserTalkUpdate( 1, $this->mTitle->getNamespace(), $shortTitle );
1673 array_push( $wgDeferredUpdateList, $u );
1674
1675 if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
1676 $wgMessageCache->replace( $shortTitle, $text );
1677 }
1678 }
1679 }
1680
1681 /* private */ function setOldSubtitle()
1682 {
1683 global $wgLang, $wgOut;
1684
1685 $td = $wgLang->timeanddate( $this->mTimestamp, true );
1686 $r = wfMsg( 'revisionasof', $td );
1687 $wgOut->setSubtitle( "({$r})" );
1688 }
1689
1690 # This function is called right before saving the wikitext,
1691 # so we can do things like signatures and links-in-context.
1692
1693 function preSaveTransform( $text )
1694 {
1695 global $wgParser, $wgUser;
1696 return $wgParser->preSaveTransform( $text, $this->mTitle, $wgUser, ParserOptions::newFromUser( $wgUser ) );
1697 }
1698
1699 /* Caching functions */
1700
1701 # checkLastModified returns true if it has taken care of all
1702 # output to the client that is necessary for this request.
1703 # (that is, it has sent a cached version of the page)
1704 function tryFileCache() {
1705 static $called = false;
1706 if( $called ) {
1707 wfDebug( " tryFileCache() -- called twice!?\n" );
1708 return;
1709 }
1710 $called = true;
1711 if($this->isFileCacheable()) {
1712 $touched = $this->mTouched;
1713 if( $this->mTitle->getPrefixedDBkey() == wfMsg( 'mainpage' ) ) {
1714 # Expire the main page quicker
1715 $expire = wfUnix2Timestamp( time() - 3600 );
1716 $touched = max( $expire, $touched );
1717 }
1718 $cache = new CacheManager( $this->mTitle );
1719 if($cache->isFileCacheGood( $touched )) {
1720 global $wgOut;
1721 wfDebug( " tryFileCache() - about to load\n" );
1722 $cache->loadFromFileCache();
1723 return true;
1724 } else {
1725 wfDebug( " tryFileCache() - starting buffer\n" );
1726 ob_start( array(&$cache, 'saveToFileCache' ) );
1727 }
1728 } else {
1729 wfDebug( " tryFileCache() - not cacheable\n" );
1730 }
1731 }
1732
1733 function isFileCacheable() {
1734 global $wgUser, $wgUseFileCache, $wgShowIPinHeader, $wgRequest;
1735 extract( $wgRequest->getValues( 'action', 'oldid', 'diff', 'redirect', 'printable' ) );
1736
1737 return $wgUseFileCache
1738 and (!$wgShowIPinHeader)
1739 and ($this->getID() != 0)
1740 and ($wgUser->getId() == 0)
1741 and (!$wgUser->getNewtalk())
1742 and ($this->mTitle->getNamespace() != Namespace::getSpecial())
1743 and ($action == 'view' || empty( $action ))
1744 and (!isset($oldid))
1745 and (!isset($diff))
1746 and (!isset($redirect))
1747 and (!isset($printable))
1748 and (!$this->mRedirectedFrom);
1749 }
1750
1751 # Loads cur_touched and returns a value indicating if it should be used
1752 function checkTouched() {
1753 $fname = 'Article::checkTouched';
1754
1755 $id = $this->getID();
1756 $dbr =& wfGetDB( DB_SLAVE );
1757 $s = $dbr->getArray( 'cur', array( 'cur_touched', 'cur_is_redirect' ),
1758 array( 'cur_id' => $id ), $fname );
1759 if( $s !== false ) {
1760 $this->mTouched = $s->cur_touched;
1761 return !$s->cur_is_redirect;
1762 } else {
1763 return false;
1764 }
1765 }
1766
1767 # Edit an article without doing all that other stuff
1768 function quickEdit( $text, $comment = '', $minor = 0 ) {
1769 global $wgUser, $wgMwRedir;
1770 $fname = 'Article::quickEdit';
1771 wfProfileIn( $fname );
1772
1773 $dbw =& wfGetDB( DB_MASTER );
1774 $ns = $this->mTitle->getNamespace();
1775 $dbkey = $this->mTitle->getDBkey();
1776 $encDbKey = $dbw->strencode( $dbkey );
1777 $timestamp = wfTimestampNow();
1778
1779 # Save to history
1780 $dbw->insertSelect( 'old', 'cur',
1781 array(
1782 'old_namespace' => 'cur_namespace',
1783 'old_title' => 'cur_title',
1784 'old_text' => 'cur_text',
1785 'old_comment' => 'cur_comment',
1786 'old_user' => 'cur_user',
1787 'old_user_text' => 'cur_user_text',
1788 'old_timestamp' => 'cur_timestamp',
1789 'inverse_timestamp' => '99999999999999-cur_timestamp',
1790 ), array(
1791 'cur_namespace' => $ns,
1792 'cur_title' => $dbkey,
1793 ), $fname
1794 );
1795
1796 # Use the affected row count to determine if the article is new
1797 $numRows = $dbw->affectedRows();
1798
1799 # Make an array of fields to be inserted
1800 $fields = array(
1801 'cur_text' => $text,
1802 'cur_timestamp' => $timestamp,
1803 'cur_user' => $wgUser->getID(),
1804 'cur_user_text' => $wgUser->getName(),
1805 'inverse_timestamp' => wfInvertTimestamp( $timestamp ),
1806 'cur_comment' => $comment,
1807 'cur_is_redirect' => $wgMwRedir->matchStart( $text ) ? 1 : 0,
1808 'cur_minor_edit' => intval($minor),
1809 'cur_touched' => $timestamp,
1810 );
1811
1812 if ( $numRows ) {
1813 # Update article
1814 $fields['cur_is_new'] = 0;
1815 $dbw->updateArray( 'cur', $fields, array( 'cur_namespace' => $ns, 'cur_title' => $dbkey ), $fname );
1816 } else {
1817 # Insert new article
1818 $fields['cur_is_new'] = 1;
1819 $fields['cur_namespace'] = $ns;
1820 $fields['cur_title'] = $dbkey;
1821 $fields['cur_random'] = $rand = number_format( mt_rand() / mt_getrandmax(), 12, '.', '' );
1822 $dbw->insertArray( 'cur', $fields, $fname );
1823 }
1824 wfProfileOut( $fname );
1825 }
1826
1827 /* static */ function incViewCount( $id )
1828 {
1829 $id = intval( $id );
1830 global $wgHitcounterUpdateFreq;
1831
1832 $dbw =& wfGetDB( DB_MASTER );
1833 $curTable = $dbw->tableName( 'cur' );
1834 $hitcounterTable = $dbw->tableName( 'hitcounter' );
1835 $acchitsTable = $dbw->tableName( 'acchits' );
1836
1837 if( $wgHitcounterUpdateFreq <= 1 ){ //
1838 $dbw->query( "UPDATE $curTable SET cur_counter = cur_counter + 1 WHERE cur_id = $id" );
1839 return;
1840 }
1841
1842 # Not important enough to warrant an error page in case of failure
1843 $oldignore = $dbw->setIgnoreErrors( true );
1844
1845 $dbw->query( "INSERT INTO $hitcounterTable (hc_id) VALUES ({$id})" );
1846
1847 $checkfreq = intval( $wgHitcounterUpdateFreq/25 + 1 );
1848 if( (rand() % $checkfreq != 0) or ($dbw->lastErrno() != 0) ){
1849 # Most of the time (or on SQL errors), skip row count check
1850 $dbw->setIgnoreErrors( $oldignore );
1851 return;
1852 }
1853
1854 $res = $dbw->query("SELECT COUNT(*) as n FROM $hitcounterTable");
1855 $row = $dbw->fetchObject( $res );
1856 $rown = intval( $row->n );
1857 if( $rown >= $wgHitcounterUpdateFreq ){
1858 wfProfileIn( 'Article::incViewCount-collect' );
1859 $old_user_abort = ignore_user_abort( true );
1860
1861 $dbw->query("LOCK TABLES $hitcounterTable WRITE");
1862 $dbw->query("CREATE TEMPORARY TABLE $acchitsTable TYPE=HEAP ".
1863 "SELECT hc_id,COUNT(*) AS hc_n FROM $hitcounterTable ".
1864 'GROUP BY hc_id');
1865 $dbw->query("DELETE FROM $hitcounterTable");
1866 $dbw->query('UNLOCK TABLES');
1867 $dbw->query("UPDATE $curTable,$acchitsTable SET cur_counter=cur_counter + hc_n ".
1868 'WHERE cur_id = hc_id');
1869 $dbw->query("DROP TABLE $acchitsTable");
1870
1871 ignore_user_abort( $old_user_abort );
1872 wfProfileOut( 'Article::incViewCount-collect' );
1873 }
1874 $dbw->setIgnoreErrors( $oldignore );
1875 }
1876
1877 # The onArticle*() functions are supposed to be a kind of hooks
1878 # which should be called whenever any of the specified actions
1879 # are done.
1880 #
1881 # This is a good place to put code to clear caches, for instance.
1882
1883 # This is called on page move and undelete, as well as edit
1884 /* static */ function onArticleCreate($title_obj){
1885 global $wgUseSquid, $wgDeferredUpdateList;
1886
1887 $titles = $title_obj->getBrokenLinksTo();
1888
1889 # Purge squid
1890 if ( $wgUseSquid ) {
1891 $urls = $title_obj->getSquidURLs();
1892 foreach ( $titles as $linkTitle ) {
1893 $urls[] = $linkTitle->getInternalURL();
1894 }
1895 $u = new SquidUpdate( $urls );
1896 array_push( $wgDeferredUpdateList, $u );
1897 }
1898
1899 # Clear persistent link cache
1900 LinkCache::linksccClearBrokenLinksTo( $title_obj->getPrefixedDBkey() );
1901 }
1902
1903 /* static */ function onArticleDelete($title_obj){
1904 LinkCache::linksccClearLinksTo( $title_obj->getArticleID() );
1905 }
1906
1907 /* static */ function onArticleEdit($title_obj){
1908 LinkCache::linksccClearPage( $title_obj->getArticleID() );
1909 }
1910
1911 # Info about this page
1912
1913 function info()
1914 {
1915 global $wgUser, $wgTitle, $wgOut, $wgLang, $wgAllowPageInfo;
1916 $fname = 'Article::info';
1917
1918 if ( !$wgAllowPageInfo ) {
1919 $wgOut->errorpage( "nosuchaction", "nosuchactiontext" );
1920 return;
1921 }
1922
1923 $dbr =& wfGetDB( DB_SLAVE );
1924
1925 $basenamespace = $wgTitle->getNamespace() & (~1);
1926 $cur_clause = array( 'cur_title' => $wgTitle->getDBkey(), 'cur_namespace' => $basenamespace );
1927 $old_clause = array( 'old_title' => $wgTitle->getDBkey(), 'old_namespace' => $basenamespace );
1928 $wl_clause = array( 'wl_title' => $wgTitle->getDBkey(), 'wl_namespace' => $basenamespace );
1929 $fullTitle = $wgTitle->makeName($basenamespace, $wgTitle->getDBKey());
1930 $wgOut->setPagetitle( $fullTitle );
1931 $wgOut->setSubtitle( wfMsg( "infosubtitle" ));
1932
1933 # first, see if the page exists at all.
1934 $exists = $dbr->selectField( 'cur', 'COUNT(*)', $cur_clause, $fname );
1935 if ($exists < 1) {
1936 $wgOut->addHTML( wfMsg("noarticletext") );
1937 } else {
1938 $numwatchers = $dbr->selectField( 'watchlist', 'COUNT(*)', $wl_clause, $fname );
1939 $wgOut->addHTML( "<ul><li>" . wfMsg("numwatchers", $numwatchers) . "</li>" );
1940 $old = $dbr->selectField( 'old', 'COUNT(*)', $old_clause, $fname );
1941 $wgOut->addHTML( "<li>" . wfMsg("numedits", $old + 1) . "</li>");
1942
1943 # to find number of distinct authors, we need to do some
1944 # funny stuff because of the cur/old table split:
1945 # - first, find the name of the 'cur' author
1946 # - then, find the number of *other* authors in 'old'
1947
1948 # find 'cur' author
1949 $cur_author = $dbr->selectField( 'cur', 'cur_user_text', $cur_clause, $fname );
1950
1951 # find number of 'old' authors excluding 'cur' author
1952 $authors = $dbr->selectField( 'old', 'COUNT(DISTINCT old_user_text)',
1953 $old_clause + array( 'old_user_text<>' . $dbr->addQuotes( $cur_author ) ), $fname ) + 1;
1954
1955 # now for the Talk page ...
1956 $cur_clause = array( 'cur_title' => $wgTitle->getDBkey(), 'cur_namespace' => $basenamespace+1 );
1957 $old_clause = array( 'old_title' => $wgTitle->getDBkey(), 'old_namespace' => $basenamespace+1 );
1958
1959 # does it exist?
1960 $exists = $dbr->selectField( 'cur', 'COUNT(*)', $cur_clause, $fname );
1961
1962 # number of edits
1963 if ($exists > 0) {
1964 $old = $dbr->selectField( 'old', 'COUNT(*)', $old_clause, $fname );
1965 $wgOut->addHTML( "<li>" . wfMsg("numtalkedits", $old + 1) . "</li>");
1966 }
1967 $wgOut->addHTML( "<li>" . wfMsg("numauthors", $authors) . "</li>" );
1968
1969 # number of authors
1970 if ($exists > 0) {
1971 $cur_author = $dbr->selectField( 'cur', 'cur_user_text', $cur_clause, $fname );
1972 $authors = $dbr->selectField( 'cur', 'COUNT(DISTINCT old_user_text)',
1973 $old_clause + array( 'old_user_text<>' . $dbr->addQuotes( $cur_author ) ), $fname );
1974
1975 $wgOut->addHTML( "<li>" . wfMsg("numtalkauthors", $authors) . "</li></ul>" );
1976 }
1977 }
1978 }
1979 }
1980
1981 ?>